package com.yztc.ui.cook;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.yztc.bean.cook.CookerListBean;
import com.yztc.chunboapp.R;
import com.yztc.ui.cook.jiekou.OnItemClickListener;
import com.yztc.utils.ImageHelper;

import java.util.List;


/**
 * Created by My on 2016/10/10.
 */
public class CookerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<CookerListBean> list;
    private LayoutInflater inflater;
    private OnItemClickListener listener;
    public void setListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    public CookerAdapter(Context mContext, List<CookerListBean> list) {
        this.mContext = mContext;
        this.list = list;
        Log.i("wx","-------list   CookerListBean-------"+list.size());
        inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.fragment_cook_recycleview_itme2, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
        final MyViewHolder mHolder = (MyViewHolder) holder;
        mHolder.tv_cookername_recycleview2.setText(list.get(position).getName());
        mHolder.tv_cookerinfo_recycleview2.setText(list.get(position).getSummary());
        if(listener!=null){
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos=mHolder.getLayoutPosition();
                    listener.onItemClick(holder.itemView,pos);
                }
            });
        }
        ImageHelper.getRoundImage(mContext,list.get(position).getPicUrl(),mHolder.img_cooker_recycleview2);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    class MyViewHolder extends RecyclerView.ViewHolder {
        private ImageView img_cooker_recycleview2;
        private TextView tv_cookername_recycleview2;
        private TextView tv_cookerinfo_recycleview2;

        public MyViewHolder(View itemView) {
            super(itemView);
            img_cooker_recycleview2 =
                    (ImageView) itemView.findViewById(R.id.img_cooker_recycleview2);
            tv_cookername_recycleview2 =
                    (TextView) itemView.findViewById(R.id.tv_cookername_recycleview2);
            tv_cookerinfo_recycleview2 =
                    (TextView) itemView.findViewById(R.id.tv_cookerinfo_recycleview2);
        }
    }
}
